package innerclassdemo;

import java.io.FilterOutputStream;

//public class OutercClass {
//    public int data1 = 1;
//    public int data2 = 2;
//    public static int data3 = 3;
//
//    class InnerClass{
//        public int data1 = 11111;
//        public int data4 = 4;
//        private int data5 = 5;
//        public static final int data6 = 6;
//
//        public InnerClass(){
//            System.out.println("InnerClass::init()");
//        }
//
//        public void test(){
//            System.out.println(data1);
//            System.out.println(OutercClass.this.data1);
//            //实例内部类中包括外部类的this
//        }
//    }
//}
class OuterClass {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;
    /*
    * 静态内部类：
    * 1.如何拿到静态内部类的对象？
    * OutercClass.InnerClass innerClass = new OutercClass.InnerClass();
    *2.不能在静态内部类当中，直接访问外部类非静态的数据成员
     * */
    static class InnerClass {
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;
        public OuterClass outerClass;

        public InnerClass(OuterClass outerClass){
            System.out.println("静态内部类的构造方法！");
            this.outerClass = outerClass;
        }
        public void test(){
            System.out.println("test方法执行了！");
//          OuterClass outerClass = new OuterClass();
//          System.out.println(outerClass.data1);
//          System.out.println(outerClass.data2);
            System.out.println();
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }
}
class Test{
    public static void main(String[] args) {
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass(new OuterClass());
        innerClass.test();

    }
    public static void main1(String[] args) {
//        OutercClass outercClass = new OutercClass();
//        OutercClass.InnerClass innerClass = outercClass.new InnerClass();
//        innerClass.test();
    }
}
